package org.example.myleet.p868;

public class Solution {
    public int binaryGap(int n) {
        int i = 0;
        while (0 == (n & 1)) {
            n >>>= 1;
            ++i;
        }
        int lastBit = i, maxLen = 0;
        while (n > 0) {
            n >>>= 1;
            ++i;
            if (1 == (n & 1)) {
                maxLen = Math.max(maxLen, i - lastBit);
                lastBit = i;
            }
        }
        return maxLen;
    }
}
